package com.aistar.controller;

import com.aistar.pojo.TravPraise;
import com.aistar.pojo.Travelnote;
import com.aistar.service.redis.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class TravPraiseController {
    @Autowired
    RedisService redisService;
    //游记列表跳转游记详情的点赞渲染
    @RequestMapping("traveldetails/traveldetailsup/{userId}/{noteId}")
    public ModelAndView travelDetails(@PathVariable("userId") Integer userId, @PathVariable("noteId") Integer noteId) {

        TravPraise travPraise = redisService.selectStatuspraiseTravIdByAndUserId(noteId,userId);
        int upNum = redisService.selectNumBytravId(noteId);
        int status = 1;
        if (travPraise == null){
            status = 0;
        }else{
            status = travPraise.getPraiseStatus();
        }
        System.out.println("status = " + status);
        ModelAndView mov = new ModelAndView();
        mov.addObject("upNum",upNum);
        mov.addObject("status", status);
        mov.setViewName("traveldetails/traveldetails");
        return mov;
    }
    @RequestMapping("truetravPraise/up")
    @ResponseBody
    public int ThumbsUp(int userId,int noteId){
        //从session中获取
        //String userId = String.valueOf(session.getAttribute("userId"));
        redisService.saveLiked(String.valueOf(userId),String.valueOf(noteId));
        return 0;
    }
    @RequestMapping("TruetravPraise/down")
    @ResponseBody
    public int cancelThumbsUp(int userId,int noteId){
        redisService.unLiked(String.valueOf(userId),String.valueOf(noteId));
        return 0;
    }

}
